package com.itfenghuang.day13;
//厨子  生产者
public class A02_Cook extends Thread{
    @Override
    public void run() {
        while (true){
            synchronized (A02_Desk.obj){
                if (A02_Desk.num==0){
                    break;
                }
                else {
                    //判断桌子上有没有面包
                    if (!A02_Desk.flag){
                        //厨子生产面包
                        System.out.println("厨子生产面包");
                        A02_Desk.num--;
                        //面包放到桌子上
                        //修改状态
                        A02_Desk.flag=true;
                        //唤醒吃货
                        A02_Desk.obj.notifyAll();
                    }else {
                        //有面包  等待
                        try {
                            A02_Desk.obj.wait();
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }

                }
            }
        }
    }
}
